//
//  SEGCommonDoorSubView.m
//  Commom
//
//  Created by Clavis on 2019/7/10.
//

#import "SEGCommonDoorSubView.h"

@interface SEGCommonDoorSubView ()

@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *nameLabel;

@end

@implementation SEGCommonDoorSubView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.iconImageView = ({
        UIImageView *imageView = [[UIImageView alloc] init];
        [self addSubview:imageView];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.clipsToBounds = YES;
        imageView.image = [UIImage imageWithContentsOfFile:SEGPicName(@"btn_opendoor_img_major")];
        imageView;
    });
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.centerX.mas_offset(0);
        make.width.height.mas_equalTo(60);
    }];
    
    self.nameLabel = ({
        UILabel *label = [[UILabel alloc] init];
        [self addSubview:label];
        label.textColor = kColor_1;
        label.font = kFont_14;
        label.numberOfLines = 2;
        label.textAlignment = NSTextAlignmentCenter;
        label;
    });
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImageView.mas_bottom).offset(10);
        make.left.mas_equalTo(14);
        make.right.mas_equalTo(-14);
    }];
    
    UIButton *button = ({
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self action:@selector(buttonTap:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
        button;
    });
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}

- (void)updateUIWithModel:(SEGNewMyDoorListModel *)doorModel {
    self.nameLabel.text = doorModel.name;
}

- (void)buttonTap:(UIButton *)sender {
    if (self.clickBlock) {
        self.clickBlock();
    }
}

@end
